#ifndef     __AUDIO_PARAM_H
#define     __AUDIO_PARAM_H

#include <SDL2/SDL.h>
extern "C" {
#include <libavcodec/avcodec.h>
}
#include "./error.h"

struct AudioParam {

    AudioParam(AVCodecContext *ctx) {
        sample_rate = ctx->sample_rate;
        sample_chan = ctx->ch_layout.nb_channels;
        
        switch (ctx->sample_fmt) {
            case AV_SAMPLE_FMT_U8:
            case AV_SAMPLE_FMT_U8P:
                sample_fmt = AUDIO_U8;
            break;

            case AV_SAMPLE_FMT_S16:
            case AV_SAMPLE_FMT_S16P:
                sample_fmt = AUDIO_U16SYS;
            break;

            case AV_SAMPLE_FMT_S32:
            case AV_SAMPLE_FMT_S32P:
                sample_fmt = AUDIO_S32SYS;
            break;

            case AV_SAMPLE_FMT_FLT:
            case AV_SAMPLE_FMT_FLTP:
                sample_fmt = AUDIO_F32SYS;
            break;

            default:
                throw FFmpegException("音频格式不支持");
            break;
        }
    }

    int sample_rate;
    int sample_fmt;
    int sample_chan;
};


#endif
